var mixin = {
    data: () => {
        return {
            apiUrl: {
                login:'/dsp/user/login',
                adDisplaydata:'/dsp/ad/displaydata',
                adGetdeposit:'/dsp/deposit/getadvdeposit',
                groupAdDisplay: '/dsp/group/addisplay',
                adAddetail: '/dsp/ad/addetail',
            }
        };
    },
    methods: {
        // 存储storage用户信息
        set_storage(str, val) {
            sessionStorage.setItem(str, val);
        },
        //设置cookie
        setCookie: function (cname, cvalue, exdays) {
            var d = new Date();
            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
            var expires = 'expires=' + d.toUTCString();
            // var domain = 'domain=' + 'http://dsp.i6bktq.cn/';
            // console.info(cname + '=' + cvalue + '; ' + expires);
            document.cookie = cname + '=' + cvalue + '; ' + expires + '; ';
            // console.info(document.cookie);
        },
        //获取cookie
        getCookie: function (cname) {
            var name = cname + '=';
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1);
                if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
            }
            return '';
        },
        //清除cookie
        clearCookie: function () {
            this.setCookie('username', '', -1);
        },
        //标准时间转常用格式
        formatDateTime(date, format) {
            if(!date){
                return '';
            }
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            minute = minute < 10 ? ('0' + minute) : minute;
            second = second < 10 ? ('0' + second) : second;
            if (format == 'y-m-d h-m-s') {
                return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
            } else if (format == 'h-m') {
                return ' ' + h + ':' + minute;
            } else if (format == 'y-m-d') {
                return y + '-' + m + '-' + d;
            } else if (format == 'y/m/d') {
                return y + '/' + m + '/' + d;
            } else if (format == 'ymd') {
                return y + '' + m + '' + d;
            }
        },
        // 导出xls数据
        handleDownload(theader, filterval, tabledata, filename) {
            this.downloadLoading = true;
            require.ensure([], () => {
                const {export_json_to_excel} = require('@/vendor/Export2Excel');
                const tHeader = theader;
                const filterVal = filterval;
                const list = tabledata;
                const data = this.formatJson(filterVal, list);
                export_json_to_excel(tHeader, data, filename);
                this.downloadLoading = false;
            });
        },
        formatJson(filterVal, jsonData) {
            return jsonData.map(v => filterVal.map(j => v[j]));
        },
    }

};
export default mixin;

